package com.hy.frame.base;

import android.os.Build;
import android.view.WindowManager;

import com.hy.frame.common.IImageLoader;
import com.hy.frame.common.ITemplateUI;

/**
 * title BaseTActivity
 * author HeYan
 * time 2020/12/2 17:14
 * desc 无
 */
public abstract class BaseTActivity<T extends ITemplateUI> extends BaseActivity {
    private IImageLoader mImageLoader = null;
    private T mTemplateUI = null;

    /**
     * 设置模板[ITemplateControl]
     */
    public abstract T buildTemplateUI();

    /**
     * 获取模板[ITemplateControl]
     */
    public T getTemplateUI() {
        return this.mTemplateUI;
    }

    /**
     * 获取图片加载器
     */
    public IImageLoader getImageLoader() {
        if (isIDestroy()) return null;
        if (this.mImageLoader == null)
            this.mImageLoader = buildImageLoader();
        return this.mImageLoader;
    }

    public abstract IImageLoader buildImageLoader();


    @Override
    public void initLayout() {
        T mTemplateUI = buildTemplateUI();
        if (mTemplateUI != null) {
            mTemplateUI.initLayout();
            setContentView(mTemplateUI.getRootLayout());
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                if (mTemplateUI.isTranslucentStatus()) {
                    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                } else {
                    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                }
            }
        }
        this.mTemplateUI = mTemplateUI;
    }

    @Override
    public void initView() {
        ITemplateUI mTemplateUI = getTemplateUI();
        if (mTemplateUI != null) {
            mTemplateUI.initView();
        }
    }

    @Override
    public void initData() {
        ITemplateUI mTemplateUI = getTemplateUI();
        if (mTemplateUI != null) {
            mTemplateUI.initData();
        }
    }
}
